package com.yunao.web.utils;

import com.yunao.commons.serachcore.core.bean.*;
import com.yunao.commons.serachcore.core.help.GroupField;
import com.yunao.commons.serachcore.core.help.SearchFiled;
import com.yunao.commons.utils.DomainSourceUtils;
import com.yunao.service.report.esou.ItextUtil;
import com.yunao.web.controller.ReportAction;
import freemarker.template.Configuration;
import freemarker.template.Template;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.CategoryAxis;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.RingPlot;
import org.jfree.chart.renderer.category.LineAndShapeRenderer;
import org.jfree.chart.title.LegendTitle;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.ui.RectangleEdge;
import sun.misc.BASE64Encoder;

import java.awt.*;
import java.io.*;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ImReportUtil {

    static Group tieba;
    static Group weibo;
    static Group forum;
    static Group website;
    static Group news;
    static Group paper;
    static Group gvm;
    static Group client;
    static Group blog;
    static Group video;
    static Group tv;

    public static File currentImReport(Groups mediatypeGroups, Groups hostGroups, Groups emotionGroups, Cubes mediadayCube, Groups authorGroups, Clusters posClusters, Clusters negClusters)throws Exception{

        List<Group> accountList = new ArrayList<>();//敏感账号
        List<Cluster> posList = new ArrayList<>();//热门文章
        List<Cluster> negList = new ArrayList<>();//负面文章 排序

        List<Group> mtgroupsList = mediatypeGroups.getData();
        mtgroupsList.stream().forEach(
                e -> {
                    if(e.getKey().equalsIgnoreCase("贴吧")){
                        tieba = e;
                    }else if (e.getKey().equalsIgnoreCase("微博")){
                        weibo = e;
                    }else if (e.getKey().equalsIgnoreCase("论坛")){
                        forum = e;
                    }else if (e.getKey().equalsIgnoreCase("网站")){
                        website = e;
                    }else if (e.getKey().equalsIgnoreCase("新闻")){
                        news = e;
                    }else if (e.getKey().equalsIgnoreCase("电子报")){
                        paper = e;
                    }else if (e.getKey().equalsIgnoreCase("政务")){
                        gvm = e;
                    }else if (e.getKey().equalsIgnoreCase("客户端")){
                        client = e;
                    }else if (e.getKey().equalsIgnoreCase("博客")){
                        blog = e;
                    }else if(e.getKey().equalsIgnoreCase("视频")){
                        video = e;
                    }else if(e.getKey().equalsIgnoreCase("电视")){
                        tv = e ;
                    }
                }
        );
        mediatypeGroups.sortByValue();
        mediatypeGroups.getData().get(0).getKey();
        accountList = authorGroups.getData();
        //正面文章热度
        if(posClusters!=null){
            posList = posClusters.getData();
        }
        //负面文章热度
        if(negClusters!=null){
            negList = negClusters.getData();
        }

        //添加word数据
        Map<String, Object> dataMap = new HashMap<>();
        dataMap.put("total",mediatypeGroups.getTotal());
        if(blog!=null){
            dataMap.put("blog",blog.getValue());
            dataMap.put("blogPercent",getPercent(blog.getValue(),mediatypeGroups.getTotal()));
        }else{
            dataMap.put("blog","0");
            dataMap.put("blogPercent","0");
        }

        if(weibo!=null){
            dataMap.put("weibo",weibo.getValue());
            dataMap.put("weiboPercent",getPercent(weibo.getValue(),mediatypeGroups.getTotal()));
        }else {
            dataMap.put("weibo","0");
            dataMap.put("weiboPercent","0");
        }

        if(news!=null){
            dataMap.put("news",news.getValue());
            dataMap.put("newsPercent",getPercent(news.getValue(),mediatypeGroups.getTotal()));
        }else{
            dataMap.put("news","0");
            dataMap.put("newsPercent","0");
        }

        if(forum!=null){
            dataMap.put("forum",forum.getValue());
            dataMap.put("forumPercent",getPercent(forum.getValue(),mediatypeGroups.getTotal()));
        }else {
            dataMap.put("forum","0");
            dataMap.put("forumPercent","0");
        }

        dataMap.put("max", mediatypeGroups.getData().get(0).getValue());
        dataMap.put("maxName", mediatypeGroups.getData().get(0).getKey());
        dataMap.put("maxPercent", getPercent(mediatypeGroups.getData().get(0).getValue(), mediatypeGroups.getTotal()));

        if(hostGroups.getData().size()>=1&&hostGroups.getData().get(0).getKey()!=null) {
            dataMap.put("website1", DomainSourceUtils.getSource(hostGroups.getData().get(0).getKey()));
        }else{
            dataMap.put("website1", "【无数据】");
        }
        if(hostGroups.getData().size()>=2&&hostGroups.getData().get(1).getKey()!=null) {
            dataMap.put("website2", DomainSourceUtils.getSource(hostGroups.getData().get(1).getKey()));
        }else{
            dataMap.put("website2", "【无数据】");
        }
        if(hostGroups.getData().size()>=3&&hostGroups.getData().get(2).getKey()!=null) {
            dataMap.put("website3", DomainSourceUtils.getSource(hostGroups.getData().get(2).getKey()));
        }else{
            dataMap.put("website3", "【无数据】");
        }
        if(hostGroups.getData().size()>=4&&hostGroups.getData().get(3).getKey()!=null) {
            dataMap.put("website4", DomainSourceUtils.getSource(hostGroups.getData().get(3).getKey()));
        }else{
            dataMap.put("website4", "【无数据】");
        }
        if(hostGroups.getData().size()>=5&&hostGroups.getData().get(4).getKey()!=null) {
            dataMap.put("website5", DomainSourceUtils.getSource(hostGroups.getData().get(4).getKey()));
        }else{
            dataMap.put("website5", "【无数据】");
        }
        if(hostGroups.getData().size()>=6&&hostGroups.getData().get(5).getKey()!=null) {
            dataMap.put("website6", DomainSourceUtils.getSource(hostGroups.getData().get(5).getKey()));
        }else{
            dataMap.put("website6", "【无数据】");
        }
        //事件走势图
        if(mediadayCube!=null){
            dataMap.put("qushitu",getImageStr(getTrend(getTrendData(mediadayCube))));
        }else {
            dataMap.put("qushitu","【无数据】");
        }
        //饼图
        if(mediatypeGroups!=null){
            dataMap.put("mediabingtu",getImageStr(getPie(getPieData(mediatypeGroups))));
        }else {
            dataMap.put("mediabingtu","【无数据】");
        }

        if(emotionGroups!=null){
            dataMap.put("emotionbingtu",getImageStr(getPie(getPieData(emotionGroups))));
        }else {
            dataMap.put("emotionbingtu","【无数据】");
        }
        //媒体走势
        if(mediadayCube!=null) {
            dataMap.put("data1", mediadayCube.getData().get(0).getKey());
            if (mediadayCube.getData().size() > 1) {
                dataMap.put("data2", "至" + mediadayCube.getData().get(mediadayCube.getData().size() - 1).getKey());
            } else {
                dataMap.put("data2", "");
            }
        }else{
            dataMap.put("data1","【无数据】");
        }

        if(weibo!=null){
            dataMap.put("weibo",weibo.getValue());
            dataMap.put("weiboPercent",getPercent(weibo.getValue(),mediatypeGroups.getTotal()));
        }else {
            dataMap.put("weibo","0");
            dataMap.put("weiboPercent","0");
        }

        if(tieba!=null){
            dataMap.put("tieba",tieba.getValue());
            dataMap.put("tiebaPercent",getPercent(tieba.getValue(),mediatypeGroups.getTotal()));
        }else{
            dataMap.put("tieba","0");
            dataMap.put("tiebaPercent","0");
        }

        if(website!=null){
            dataMap.put("website",website.getValue());
            dataMap.put("websitePercent",getPercent(website.getValue(),mediatypeGroups.getTotal()));
        }else {
            dataMap.put("website","0");
            dataMap.put("websitePercent","0");
        }

        if(paper!=null){
            dataMap.put("paper",paper.getValue());
            dataMap.put("paperPercent",getPercent(paper.getValue(),mediatypeGroups.getTotal()));
        }else {
            dataMap.put("paper","0");
            dataMap.put("paperPercent","0");
        }

        if(gvm!=null){
            dataMap.put("gvm",gvm.getValue());
            dataMap.put("gvmPercent",getPercent(gvm.getValue(),mediatypeGroups.getTotal()));
        }else {
            dataMap.put("gvm","0");
            dataMap.put("gvmPercent","0");
        }

        if(client!=null){
            dataMap.put("client",client.getValue());
            dataMap.put("clientPercent",getPercent(client.getValue(),mediatypeGroups.getTotal()));
        }else {
            dataMap.put("client","0");
            dataMap.put("clientPercent","0");
        }

        if(tv!=null){
            dataMap.put("tv",tv.getValue());
            dataMap.put("tvPercent",getPercent(tv.getValue(),mediatypeGroups.getTotal()));
        }else {
            dataMap.put("tv","0");
            dataMap.put("tvPercent","0");
        }

        if(video!=null){
            dataMap.put("video",video.getValue());
            dataMap.put("videoPercent",getPercent(video.getValue(),mediatypeGroups.getTotal()));
        }else {
            dataMap.put("video","0");
            dataMap.put("videoPercent","0");
        }

        //情感属性
        if(emotionGroups.getData().size()>=1&&emotionGroups.getData().get(0)!=null){
            dataMap.put("neutralName",emotionGroups.getData().get(0).getKey());
            dataMap.put("neutral",emotionGroups.getData().get(0).getValue());
            dataMap.put("neutralPercent",getPercent(emotionGroups.getData().get(0).getValue(),emotionGroups.getTotal()));
        }else {
            dataMap.put("neutralName","【无数据】");
            dataMap.put("neutral",0);
            dataMap.put("neutralPercent",0);
        }

        if(emotionGroups.getData().size()>=2&&emotionGroups.getData().get(1)!=null){
            dataMap.put("positiveName",emotionGroups.getData().get(1).getKey());
            dataMap.put("positive",emotionGroups.getData().get(1).getValue());
            dataMap.put("positivePercent",getPercent(emotionGroups.getData().get(1).getValue(),emotionGroups.getTotal()));
        }else {
            dataMap.put("positiveName","【无数据】");
            dataMap.put("positive",0);
            dataMap.put("positivePercent",0);
        }

        if(emotionGroups.getData().size()>=3&&emotionGroups.getData().get(2)!=null){
            dataMap.put("negativeName",emotionGroups.getData().get(2).getKey());
            dataMap.put("negative",emotionGroups.getData().get(2).getValue());
            dataMap.put("negativePercent",getPercent(emotionGroups.getData().get(2).getValue(),emotionGroups.getTotal()));
        }else {
            dataMap.put("negativeName","【无数据】");
            dataMap.put("negative",0);
            dataMap.put("negativePercent",0);
        }

        //敏感账号
        if(accountList!=null){
            dataMap.put("accounList",accountList);
        }else {
            ArrayList<Group> list = new ArrayList<>();
            Group group = new Group();
            group.setKey("【无数据】");
            group.setValue(0);
            list.add(group);
            dataMap.put("accounList",list);
        }

        //热门文章
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if(posList!=null){
            List<DocBean> pos =  new ArrayList<>();
            posList.stream().forEach(
                    e -> {
                        DocBean docBean = new DocBean();
                        docBean.setPhrase(e.getWords().get(0)+"+"+e.getWords().get(1)+"+"+e.getWords().get(2));
                        docBean.setMediaType(e.getDocs().get(0).getMediaType());
                        docBean.setPubdate(sdf.format(e.getDocs().get(0).getPubdate()));
                        docBean.setSame((int)(e.getDocPercent()*posClusters.getTotal()));
                        docBean.setTitle(e.getDocs().get(0).getTitle());
                        pos.add(docBean);
                    }
            );
            dataMap.put("posList",pos);
        }else {
            ArrayList<DocBean> list = new ArrayList<>();
            DocBean doc = new DocBean();
            doc.setTitle("【无数据】");
            doc.setSame(0);
            doc.setPubdate("【无数据】");
            doc.setMediaType("【无数据】");
            doc.setPhrase("【无数据】");
            list.add(doc);
            dataMap.put("posList",list);
        }
        if(negList!=null) {
            //负面文章
            List<DocBean> neg = new ArrayList<>();
            negList.stream().forEach(
                    e -> {
                        DocBean docBean = new DocBean();
                        docBean.setPhrase(e.getWords().get(0) + "+" + e.getWords().get(1) + "+" + e.getWords().get(2));
                        docBean.setMediaType(e.getDocs().get(0).getMediaType());
                        docBean.setPubdate(sdf.format(e.getDocs().get(0).getPubdate()));
                        docBean.setSame((int) (e.getDocPercent() * negClusters.getTotal()));
                        docBean.setTitle(e.getDocs().get(0).getTitle());
                        neg.add(docBean);
                    }
            );
            dataMap.put("negList", neg);
        }else {
            ArrayList<DocBean> list = new ArrayList<>();
            DocBean doc = new DocBean();
            doc.setTitle("【无数据】");
            doc.setSame(0);
            doc.setPubdate("【无数据】");
            doc.setMediaType("【无数据】");
            doc.setPhrase("【无数据】");
            list.add(doc);
            dataMap.put("negList",list);
        }
        //生成报告
        Configuration configuration = new Configuration();
        configuration.setDefaultEncoding("utf-8");
        configuration.setClassForTemplateLoading(ReportAction.class, "/templates/code");
        Template template = null;
        try {
            template = configuration.getTemplate("temp_doc.ftl");
        } catch (IOException e) {
            e.printStackTrace();
        }
        File outFile = new File(ItextUtil.docpath()+System.currentTimeMillis()+".doc");
        Writer out = null;
        try {
            out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outFile),"UTF-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        try {
            template.process(dataMap,out);
            out.flush();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return outFile;
    }
    public static String getImageStr(String imgFile) {
        InputStream in = null;
        byte[] data = null;
        try {
            in = new FileInputStream(imgFile);
            data = new byte[in.available()];
            in.read(data);
            in.close();
        } catch (Exception e) {

        }
        BASE64Encoder encoder = new BASE64Encoder();
        return encoder.encode(data);
    }

    static NumberFormat numberFormat = NumberFormat.getInstance();
    //百分比
    private static String getPercent(long a,long b){
        numberFormat.setMaximumFractionDigits(2);
        String format = numberFormat.format((float) a / (float) b * 100);
        if(format.equalsIgnoreCase("0")&&a>0l){
            format = "0.01";
        }
        return format;
    }

    //生成饼图
    private static String getPie(DefaultPieDataset dataset){
        JFreeChart chart= ChartFactory.createRingChart(null,dataset,true,true,false);
        //第一个参数是标题，第二个参数是一个数据集，第三个参数表示是否显示Legend，第四个参数表示是否显示提示，第五个参数表示图中是否存在URL

        Font font = new Font("宋体", Font.BOLD, 18);
        RingPlot plot = (RingPlot) chart.getPlot();
        //设置外廓
        plot.setSectionOutlinesVisible(false);
        //数据区的边界线条颜色
        plot.setOutlinePaint(Color.WHITE);
        //设置图例地址
        LegendTitle legend = chart.getLegend(0);
        legend.setBorder(0,0,0,0);
        legend.setPosition(RectangleEdge.RIGHT);//设置图例的位置
        legend.setItemFont(new Font("宋体",0,18));


        plot.setLabelOutlinePaint(null);// (1)自定义标签产生器,设置绘图面板外边的填充颜色
        plot.setLabelShadowPaint(null);//自定义标签产生器, 设置绘图面板阴影的填充颜色
        plot.setLabelOutlineStroke(null);//(2) 自定义标签产生器,设置绘图面板外边的填充颜色
        plot.setLabelBackgroundPaint(null);//自定义标签产生器,背景色
        //设置内部空心
        plot.setSectionDepth(0.3d);

        plot.setLabelFont(font);
        plot.setStartAngle(new Float(3.14f / 2f));
//        plot.setForegroundAlpha(0.7f);
        plot.setBackgroundAlpha(0.0f);
//        plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}({1}占{2})"));
        plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}{1}%"));
        String filePath = ItextUtil.docpath();
        String imgPath = filePath + System.currentTimeMillis() + "Pie.png";
        File file = new File(imgPath);
        try {
            if (!file.exists())
                file.createNewFile();
            ChartUtilities.saveChartAsPNG(file, chart, 900, 400);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return imgPath;
    }
    //生成折线图
    private static String getTrend(DefaultCategoryDataset dataset){
        // 定义图表对象数据，数据
        JFreeChart  chart = ChartFactory.createLineChart(
                null, // chart title
                null, // domain axis label
                null, // range axis label
                dataset, // data
                PlotOrientation.VERTICAL, // orientation
                true, // include legend
                true, // tooltips
                false // urls
        );
        // 改变图表的背景颜色
//        chart.setBackgroundPaint(Color.white);

        CategoryPlot plot = chart.getCategoryPlot();
        // 设置背景透明度（0~1）
        plot.setBackgroundAlpha(0f);
        // 设置前景色透明度（0~1）
        plot.setForegroundAlpha(1f);
        // 设置网格横线颜色
        plot.setRangeGridlinePaint(Color.gray);
        //数据区的边界线条颜色
        plot.setOutlinePaint(Color.WHITE);
        // 设置图示字体
//        chart.getTitle().setFont(new Font("宋体", Font.BOLD, 22));
        //设置横轴的字体
        CategoryAxis categoryAxis = plot.getDomainAxis();
        categoryAxis.setTickMarksVisible(true);//标记线是否显示
        categoryAxis.setLabelFont(new Font("宋体", Font.BOLD, 25));
        categoryAxis.setCategoryMargin(0.05);
        // 设置x轴刻度字体
        categoryAxis.setTickLabelFont(new Font("宋体", Font.BOLD, 14));
        categoryAxis.setLowerMargin(-0.05);// 左边距 边框距离
        categoryAxis.setUpperMargin(0.00);// 右边距 边框距离,防止最后边的一个数据靠近了坐标轴。
//        categoryAxis.setLabelFont(new Font("宋体", Font.BOLD, 22));//x轴标题字体

        //以下两行 设置图例的字体
        LegendTitle legend = chart.getLegend(0);
        legend.setItemFont(new Font("宋体", Font.BOLD, 18));
        legend.setBorder(0,0,0,0);
        //设置竖轴的字体
        NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        rangeAxis.setAxisLineVisible(false);//Y轴竖线是否显示
        rangeAxis.setLabelFont(new Font("宋体" , Font.BOLD , 13)); //设置数轴的字体
        rangeAxis.setTickLabelFont(new Font("宋体" , Font.BOLD , 13));

        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());//去掉竖轴字体显示不全
        rangeAxis.setAutoRangeIncludesZero(true);
        rangeAxis.setUpperMargin(0.20);
        rangeAxis.setLabelAngle(Math.PI / 2.0);

        //开启显示外廓线
        LineAndShapeRenderer lasp = (LineAndShapeRenderer) plot.getRenderer();
        //设置线条粗细
        plot.getRenderer().setStroke(new BasicStroke(3.0f));
        // 设置拐点是否可见/是否显示拐点
        lasp.setBaseShapesVisible(true);
        lasp.setUseFillPaint(true);//使用数据点颜色填充
        //使用数据点颜色填充
//        lasp.setSeriesShape(0, ShapeUtilities.createTranslatedShape());
        lasp.setSeriesFillPaint(0, Color.white);//设置填充色
        lasp.setDrawOutlines(true);//开启显示外廓线
        lasp.setBaseOutlineStroke(new BasicStroke(1.0F));//外廓线大小
        // 6. 将图形转换为图片
        String filePath = ItextUtil.docpath();
        String imgPath = filePath + System.currentTimeMillis() + ".png";
        File file = new File(imgPath);
        try {
            if (!file.exists())
                file.createNewFile();
            ChartUtilities.saveChartAsPNG(file, chart, 900, 400);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return imgPath;
    }
    //生成折线图数据
    private static DefaultCategoryDataset getTrendData(Cubes cubes){
        final int[] n = {0};
        // 横轴名称(列名称)
        String[] month = new String[cubes.getData().size()];/*        String [] month = {"08-08","08-09","08-10","08-11","08-12","08-13","08-14","08-15"};*/
        // 各曲线名称
        String [] series= {"博客","客户端","微博","政务","新闻","电子报","电视","网站","视频","论坛","贴吧"};
        //具体数据
        double [] num = new double[cubes.getData().size()*11];/*double [] num = {4,5,6,10,12,15,8,5,10,15,20,16,4,7,14,6,10,18,25,19,10,13,17,11,14,15,16,120,22,25,28,25,20,25,10,26,14,17,24,16,20,28,15,29,20,23,27,21,22,21,12,2,5,7,10,14,16,24,10,4,6,9,10,4};*/
        cubes.getData().stream().forEach(
                e -> {
                    //日期
                    String[] split = e.getKey().split("-");
                    String date = split[1]+"-"+split[2];
                    month[n[0]] = date;
                    //数值
                    List<Group> subs = e.getSubs();
                    e.getSubs().stream().forEach(
                            ee ->{
                                if(ee.getKey().equalsIgnoreCase("博客")){
                                    num[n[0]]=ee.getValue();
                                }else if(ee.getKey().equalsIgnoreCase("客户端")){
                                    num[n[0]+cubes.getData().size()*1]=ee.getValue();
                                }else if(ee.getKey().equalsIgnoreCase("微博")){
                                    num[n[0]+cubes.getData().size()*2]=ee.getValue();
                                }else if(ee.getKey().equalsIgnoreCase("政务")){
                                    num[n[0]+cubes.getData().size()*3]=ee.getValue();
                                }else if(ee.getKey().equalsIgnoreCase("新闻")){
                                    num[n[0]+cubes.getData().size()*4]=ee.getValue();
                                }else if(ee.getKey().equalsIgnoreCase("电子报")){
                                    num[n[0]+cubes.getData().size()*5]=ee.getValue();
                                }else if(ee.getKey().equalsIgnoreCase("电视")){
                                    num[n[0]+cubes.getData().size()*6]=ee.getValue();
                                }else if(ee.getKey().equalsIgnoreCase("视频")){
                                    num[n[0]+cubes.getData().size()*7]=ee.getValue();
                                }else if(ee.getKey().equalsIgnoreCase("论坛")){
                                    num[n[0]+cubes.getData().size()*8]=ee.getValue();
                                }else if(ee.getKey().equalsIgnoreCase("网站")){
                                    num[n[0]+cubes.getData().size()*9]=ee.getValue();
                                }else if(ee.getKey().equalsIgnoreCase("贴吧")){
                                    num[n[0]+cubes.getData().size()*10]=ee.getValue();
                                }
                            }
                    );
                    n[0]++;
                }
        );
        DefaultCategoryDataset trendDataset = new DefaultCategoryDataset();

        int l1 = num.length/series.length; //4
        int l2 = month.length;
        int j=0;
        for(int i=0;i<num.length;i++) {
            trendDataset.addValue(num[i], series[i/l1], month[j]);
            j++;
            if(j==month.length)
                j=0;
        }
        return trendDataset;
    }
    //生成饼图数据
    private static DefaultPieDataset getPieData(Groups groups){
        DefaultPieDataset dataset = new DefaultPieDataset();
        groups.getData().stream().forEach(
                e -> {
                    dataset.setValue(e.getKey(),Double.parseDouble(getPercent(e.getValue(),groups.getTotal())));
                }
        );
        return dataset;
    }
}
